(function () {

	var xml = require("xml");

	function transformValue(value) {
		if (value instanceof Date) return value.toISOString();
		return value;
	}

	function Serializer(){
		this.serialize = function (model) {
			if (!model) return "";
			var keys = Object.keys(model);
			var xmlObject = {};
			var arr = xmlObject[model.__type] = [];
			for (var i in keys) {
				var key = keys[i];
				if (!model.hasOwnProperty(key) || key === "__type") continue;
				var node = JSON.parse("{\"" + key + "\": null}");
				node[key] = transformValue(model[key]);
				arr.push(node);
			}
			return xml(xmlObject);
		}
	}

	module.exports = Serializer;

})();